package com.gnerv.rabbitmq.manage.service;

import com.gnerv.rabbitmq.manage.exception.ParameterException;
import com.gnerv.rabbitmq.manage.model.ResultMessage;

/**
 * @author Gnerv LiGen
 * @create 2023/8/3 15:47
 */
public class BaseService {

    public static final long MAX_SIZE = 100L;

    public Long limitStart(Long current, Long size) {
        if (current == null) {
            current = 1L;
        }
        if (current < 1 || current > Integer.MAX_VALUE) {
            throw new ParameterException(ResultMessage.PAGE_EXCEPTION);
        }
        return (current - 1L) * limitSize(size);
    }

    public Long limitSize(Long size) {
        if (size == null) {
            size = 10L;
        }
        if (size < 0 || size >= MAX_SIZE) {
            throw new ParameterException(ResultMessage.PAGE_SIZE_EXCEPTION);
        }
        return size;
    }

}
